package com.gyz.mqtt.controller;

import com.gyz.mqtt.service.IMqttSender;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 测试发送消息
 *
 * @author gong_yuzhuo
 */
@RestController
public class HelloController {

    /**
     * 注入发送MQTT的Bean
     */
    @Resource
    private IMqttSender imqttSender;

    /**
     * 发送自定义消息内容（使用默认主题）
     * @param data
     */
    @RequestMapping("/test1/{data}")
    public void test1(@PathVariable("data") String data) {
        imqttSender.sendToMqtt(data);
    }

    /**
     * 发送自定义消息内容，且指定主题
     * @param topic
     * @param data
     */
    @RequestMapping("/test2/{topic}/{data}")
    public void test2(@PathVariable("topic") String topic, @PathVariable("data") String data) {
        imqttSender.sendToMqtt(topic, data);
    }

}
